#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

//https://leetcode.cn/problems/binary-tree-preorder-traversal/submissions/419496041/?languageTags=c

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};

    void preorder(struct TreeNode* root, int* n, int* ret)
{
    if (root == NULL)
        return;
    ret[(*n)++] = root->val;
    preorder(root->left, n, ret);
    preorder(root->right, n, ret);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int* ret = (int*)malloc(500);
    *returnSize = 0;
    preorder(root, returnSize, ret);
    return ret;
}